﻿/*
 *  Author: Louis A. Leskoviansky
 *  Company: Artemis Solutions Group (http://www.artemis-solutions.com)
 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace AjaxControlFramework
{
    public class RedirectOptions
    {
        //------// Properties \\--------------------------------------------\\
        private int _pauseBeforeRedirect = 0;
        public virtual int PauseBeforeRedirect
        {
            get { return _pauseBeforeRedirect; }
            set
            {
                if (value < 0) { PauseBeforeRedirect = 0; }
                else { PauseBeforeRedirect = value; }
            }
        }


        private string _redirectUrl = null;
        public virtual string RedirectUrl
        {
            get { return _redirectUrl; }
            set
            {
                Page page = HttpContext.Current.CurrentHandler as Page;
                if (page != null)
                {
                    _redirectUrl = page.ResolveClientUrl(value);
                }
                else
                {
                    _redirectUrl = value;
                }
            }
        }
        //------\\ Properties //--------------------------------------------//



        //------// Constructors \\------------------------------------------\\
        public RedirectOptions(int pauseBeforeRedirect, string redirectUrl)
        {
            PauseBeforeRedirect = pauseBeforeRedirect;
            RedirectUrl = redirectUrl;
        }


        public RedirectOptions(TimeSpan pauseBeforeRedirect, string redirectUrl)
        {
            if (pauseBeforeRedirect == TimeSpan.MinValue || pauseBeforeRedirect == TimeSpan.MaxValue)
            {
                PauseBeforeRedirect = 0;
            }
            else
            {
                PauseBeforeRedirect = pauseBeforeRedirect.Milliseconds;
            }

            RedirectUrl = redirectUrl;
        }


        public RedirectOptions(string redirectUrl)
        {
            RedirectUrl = redirectUrl;
        }


        public RedirectOptions()
        { }
        //------\\ Constructors //------------------------------------------//
    }
}
